package cn.com.server.service.impl;

import cn.com.server.dao.ResourceDao;
import cn.com.server.entity.Resource;
import cn.com.server.entity.Role;
import cn.com.server.service.ResourceService;
import cn.com.server.extend.view.MenuView;
import cn.com.server.extend.model.ResourceModel;
import cn.com.server.extend.view.ResourceView;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * <p>
 * 资源表 服务实现类
 * </p>
 *
 * @author qing
 * @since 2017-11-20
 */
@Service
public class ResourceServiceImp implements ResourceService {
	
	@Autowired
	private ResourceDao dao;

	@Override
	public List<Resource> selectByRoleList(List<Role> roles) {
		return dao.selectByRoleList(roles);
	}
	
	@Override
	public List<MenuView> selectByMenuList(List<Role> roles,Long parentId,Integer type){
		return dao.selectByMenuList(roles, parentId, type);
	}
	
	@Override
	public Page<Resource> selectResourceList(ResourceModel model){
		PageHelper.startPage(model.getPage(), model.getLimit());
		Page<Resource> pageData = dao.selectResourceList(model);
		return pageData;
		
	}
	
	@Override
	public List<ResourceView> selectResourceViewTree(Long parentId,Integer status,Long roleId){
		return dao.selectResourceViewTree(parentId, status,roleId);
	}
	
	@Override
	public List<ResourceView> selectResourceViewTreeIteration(Long parentId,Integer status,Long roleId){
		List<ResourceView> resourceViews = dao.selectResourceViewTree(parentId,status,roleId);
		for(ResourceView rv:resourceViews) {
			rv.setChildren(selectResourceViewTreeIteration(rv.getId(),status,roleId));
		}
		return resourceViews;
	}
	
	@Override
	public int update(Resource entity) {
		return dao.update(entity);
	}
}
